// components/goods-diy/youhui/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goods: {
      type: Object,
      value: null
    },
    __wxapp_img: {
      type: Object,
      value: null
    },
    __user_info: {
      type: Object,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    coupon: [],
    show_coupon: !1
  },
  ready: function () {
    this.getInfo()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getInfo: function () {
      var n = this;
      getApp().request({
          url: getApp().api.default.get_goods_youhui,
          data: {
              id: n.data.goods.id,
          },
          success: function(t) {
            n.setData({
              list: t.data.data,
              coupon: t.data.coupon
            })
          }
      });
    },
    updateCoupon: function () {
      var that = this;
      that.setData({
        show_coupon: !that.data.show_coupon
      })
    },
    receive: function(t) {
      var user = getApp().core.getStorageSync(getApp().const.USER_INFO);
      if (!user) {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        })
        return
      }
      var o = this, e = t.target.dataset.id,index= t.target.dataset.index;
      getApp().core.showLoading({
          mask: !0
      }), getApp().request({
          url: getApp().api.coupon.receive,
          data: {
              id: e
          },
          success: function(t) {
            if (t.code == 0) {
              var coupon = o.data.coupon;
              coupon[index].is_receive = 1;
              o.setData({
                coupon: coupon
              });
            }
          },
          complete: function() {
              getApp().core.hideLoading();
          }
      });
  },
  }
})
